import pandas as pd
import numpy as np
from GCForest import gcForest
from sklearn.metrics import accuracy_score, confusion_matrix, recall_score, f1_score, precision_score
from sklearn.model_selection import train_test_split

txt = np.loadtxt('F:\\毕设\\NLP_ClusteringProject1\\reduction_tfidf.txt')
txtDF = pd.DataFrame(txt)
txtDF.to_csv('F:\\bishe\\re_data.csv', index=False)
data = pd.read_csv('F:\\bishe\\re_data.csv')
X = data.iloc[:, 0:986]
X = np.array(X)
Y = data.iloc[:, -1:]
Y = np.array(Y)
X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size=0.33)
gcf = gcForest(shape_1X=2, window=1, tolerance=0.0)
gcf.fit(X_train, pd.DataFrame(Y_train).values.ravel())
Y_pred = gcf.predict(X_test)
print('class prediction of test data is:')
print(Y_pred)
# 模型评估
acc = accuracy_score(Y_test, Y_pred)
con_Matrix = confusion_matrix(Y_test, Y_pred, labels=[0, 1, 2])
print("The confusion_matrix of GcForest is:")
print(con_Matrix)
print('Macro precision', precision_score(Y_test, Y_pred, average='macro'))
print('Macro recall', recall_score(Y_test, Y_pred, average='macro'))
print('Macro f1-score', f1_score(Y_test, Y_pred, average='macro'))
print("Test Accuracy of GcForest = {:.2f} %".format(acc * 100))
# 模型保存
# import joblib
# joblib.dump(gcf, 'my_iris_model.sav')

# 模型加载
# joblib.load('my_iris_model.sav')




